package com.bl.weilan.manager.controller.company;

import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.CompanyEntity;
import com.bl.weilan.manager.controller.BaseController;
import com.bl.weilan.service.biz.company.CompanyService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.company.*;
import com.bl.weilan.service.vo.companyfinancing.CompanyFinancingListVo;
import com.bl.weilan.service.vo.traded.TradeDListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/manager/company"})
@Api(value = "公司相关", description = "公司相关api")
public class CompanyController  extends BaseController {
    @Autowired
    CompanyService companyService;
//

    @ApiOperation(value = "获取公司列表信息", notes = "获取公司列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<CompanyListVo> companyList(
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        CompanyListVo companyListVo = companyService.getCompanyLists(pageable);

        return ApiResponseBody.createSuccessBody(companyListVo);
    }

    @ApiOperation(value = "获取一条公司详情信息", notes = "获取一条公司")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_detail"})
    public ApiResponseBody<CompanyVo> companyList(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        CompanyVo companyVo = companyService.getCompanyById(id);

        return ApiResponseBody.createSuccessBody(companyVo);
    }

    @ApiOperation(value = "获取公司id by Full name", notes = "获取公司id by Full name")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fullName", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_id_by_full"})
    public ApiResponseBody<String> company(
            @RequestParam(value = "fullName", required = true) String fullName,
            HttpServletRequest request) {

        String companyById = companyService.getCompanyId(fullName);

        return ApiResponseBody.createSuccessBody(companyById);
    }

    @ApiOperation(value = "增加公司信息", notes = "增加公司信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add"})
    public ApiResponseBody add(
            @Valid @RequestBody CompanyAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        companyService.addCompany(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除批量", notes = "删除批量 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        companyService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除一条公司信息", notes = "删除单个公司信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {


        companyService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "修改公司信息", notes = "修改公司信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify"})
    public ApiResponseBody modify(
            @Valid @RequestBody CompanyModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        companyService.modify(body);

        return ApiResponseBody.createSuccessBody(null);
    }


    @ApiOperation(value = "获取某个公司的一二三级分类信息", notes = "获取某个公司的一二三级分类信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "query", dataType = "String", defaultValue = "")})
    @GetMapping(value = {"/get_company_trades"})
    public ApiResponseBody<CompanyTradeListVo> companyTradesList(
            @RequestParam(value = "companyId", required = true, defaultValue = "") String companyId,
            HttpServletRequest request) {


        CompanyTradeListVo companyTradeListVo = companyService.getCompanyTradeList(companyId);

        return ApiResponseBody.createSuccessBody(companyTradeListVo);
    }
//
//    @ApiOperation(value = "获取某个公司某三级行业下的四级行业列表信息", notes = "获取某个公司某三级行业下的四级行业列表信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "query", dataType = "String", defaultValue = ""),
//            @ApiImplicitParam(name = "tradeCId", value = "三级行业id", required = true, paramType = "query", dataType = "String", defaultValue = "")})
//    @GetMapping(value = {"/get_company_trades"})
//    public ApiResponseBody<CompanyTradeListVo> companyTradeDList(
//            @RequestParam(value = "companyId", required = true, defaultValue = "") String companyId,
//            @RequestParam(value = "tradeCId", required = true, defaultValue = "") String tradeCId,
//
//            HttpServletRequest request) {
//
//
//        TradeDListVo tradeDListVo = companyService.getCompanyTradeDList(companyId,tradeCId);
//
//        return ApiResponseBody.createSuccessBody(tradeDListVo);
//    }
}
